﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Web.Mail;
using System.Windows.Forms;
using Tools;

namespace LightingImportTool.Help
{
    public partial class ExceptionWindow : Form
    {
        public ExceptionWindow()
        {
            InitializeComponent();
        }

        public ExceptionWindow(Exception error)
        {
            InitializeComponent();

            StringBuilder builder = new StringBuilder();
            builder.AppendLine(error.Message);
            builder.AppendLine(error.StackTrace);
            this.RBError.Text = builder.ToString();
        }

        private void SendBtn_Click(object sender, EventArgs e)
        {
            try
            {
                MailMessage mail = EmailHelper.CreateMessage();
                mail.Body = RBError.Text;
                if (!string.IsNullOrEmpty(TBBody.Text))
                {
                    mail.Body += "/n" + TBBody.Text;
                }
                string title = "中辰照明数据导入工具异常消息";
                if (!string.IsNullOrEmpty(TBTitle.Text))
                {
                    title = TBTitle.Text;
                }
                mail.Subject = "ERROR" + title;

                if (!string.IsNullOrEmpty(TBCopy.Text))
                {
                    mail.Cc = TBCopy.Text;
                }

                EmailHelper.SendMessage(mail);
            }
            catch
            {

            }

            this.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.Close();
 
        }
    }
}
